package likou.offer;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @Info:
 * @Author: 唐小尊
 * @Date: 2020/8/26  14:16
 */
public class _45 {
    public static void main(String[] args) {
        int[] nums = {3,30,34,5,9};
        System.out.println(minNumber(nums));
        System.out.println(minNumber2(nums));
    }
    public static String minNumber(int[] nums) {
        //从首位开始排序。
        List<String> list = new ArrayList<>();
        for(int i=0;i<nums.length;i++){
            list.add(String.valueOf(nums[i]));
        }
        list.sort((s1,s2)->{
            return (s1+s2).compareTo(s2+s1);
        });
        String daan = "";
        for (String str : list){
            daan = daan + str;
        }
        return daan;
    }
    public static String minNumber2(int[] nums) {
        String[] strs = new String[nums.length];
        for(int i = 0; i < nums.length; ++i) {
            strs[i] = String.valueOf(nums[i]);
        }
        Arrays.sort(strs,(o1, o2) -> {
            return (o1+o2).compareTo(o2+o1);
        });
        StringBuilder sb = new StringBuilder();
        for(String s: strs) {
            sb.append(s);
        }
        return sb.toString();
    }
}
